
import {_decorator, Color, color,v2, Vec2,Graphics} from 'cc';
import {Ball} from "../Ball";

export default class Line
{
    public points:Array<Vec2>=[];

    public beginBall:Ball=null;
    public endBall:Ball=null;

    public addPoints(x:number, y:number)
    {
        this.points.push(v2(x, y));
    }

    public setBeginBall(ball:Ball)
    {
        this.beginBall=ball;
    }

    public setEndBall(ball:Ball)
    {
        this.endBall=ball;
    }

    public draw(graphics:Graphics)
    {
        if(this.beginBall===null)
            return;
        if(this.points.length<2)
            return;

        graphics.strokeColor=this.beginBall.getStripColor();
        graphics.moveTo(this.points[0].x, this.points[0].y);
        for(let i=1;i<this.points.length;i++)
        {
            graphics.lineTo(this.points[i].x, this.points[i].y);
        }
        graphics.stroke();
    }

}

